package com.cjc.card.greeting.dto;

import com.cjc.card.greeting.entity.Taskgreetingcard;
import com.cjc.card.greeting.entity.Tasksend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public class TaskDto {

    @Autowired
    private final JdbcTemplate jdbcTemplate;

    public TaskDto(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate = jdbcTemplate;
    }

    public void insertTaskGreetingCard(Taskgreetingcard trc){
        String sql = "INSERT INTO taskgreetingcard(task_name,task_run_time,request_url,response_result) VALUES ('"+trc.getTaskName()+"',NOW(),'"+trc.getRequestUrl()+"','"+trc.getResponseResult()+"')";
        jdbcTemplate.execute(sql);
    }

    public void insertTaskSend(Tasksend send){
        String sql = "insert into tasksend(rq,teacher_name,send_state,send_result,greeting_card_local_file_path,data_time,send_time,update_time,teacher_yhh) values (?,?,?,?,?,?,?,?,?)";

        jdbcTemplate.update(sql,send.getRq(),send.getTeacherName(),send.getSendState(),send.getSendResult(),send.getGreetingCardLocalFilePath(),send.getDataTime(),send.getSendTime(),new Date(),send.getTeacherYhh());
    }

}
